PROJECT (Gel2DE)
# Well technicall you also need:
# http://cmake.org/Bug/bug.php?op=show&bugid=3582
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)


#-----------------------------------------------------------------------------
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

IF(NOT VTK_USE_HYBRID)
  MESSAGE(FATAL_ERROR "You need to turn VTK_USE_HYBRID:ON (for vtkImagePlaneWidget.h)")
ENDIF(NOT VTK_USE_HYBRID)


#-----------------------------------------------------------------------------
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})

#-----------------------------------------------------------------------------
SET (EXECUTABLE_OUTPUT_PATH ${Gel2DE_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
SET (LIBRARY_OUTPUT_PATH ${Gel2DE_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)

#-----------------------------------------------------------------------------

# The following allows you to access wxGLCanvas for GTK
IF(WIN32)
  SET(GUI_EXECUTABLE WIN32)
ELSE(WIN32)
  IF(APPLE)
    SET(GUI_EXECUTABLE MACOSX_BUNDLE)
    IF(VTK_USE_COCOA)
      SET_SOURCE_FILES_PROPERTIES(
        GelCorrelation/wxVTKRenderWindowInteractor.cxx
        PROPERTIES COMPILE_FLAGS "-ObjC++")
    ENDIF(VTK_USE_COCOA)
  ELSE(APPLE)
    # Ok X11 for sure, but just check:
    IF(NOT VTK_USE_X)
      MESSAGE(FATAL_ERROR "You need to have VTK_USE_X")
    ENDIF(NOT VTK_USE_X)
    # CMake 2.6:
    # technically those packages are not required since one can still use the Motif/X11 version and not the gtk one:
    FIND_PACKAGE(PkgConfig)
    pkg_check_modules (GTK2 gtk+-2.0)
    #MESSAGE("${GTK2_INCLUDE_DIRS}")
    INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
    LINK_LIBRARIES(${GTK2_LIBRARIES})
    # Can I require all my user to have the gl lib on linux, even if they do not really need it...
    SET(WXGLCANVASLIBS "gl")
  ENDIF(APPLE)
ENDIF(WIN32)

# wxWidgets is required to build the project
# For GTK we need a couple of stuff:
# gl: GLCanvas
# adv: wxSashLayoutWindow and such...
FIND_PACKAGE(wxWidgets COMPONENTS base core adv ${WXGLCANVASLIBS})

# wx is a pain...
# if you include glcanvas.h it include GL/glu.h ... sigh I have to install glu on my linux box:
# sudo apt-get install libglu1-mesa-dev
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=493713
IF(wxWidgets_FOUND)
  INCLUDE( ${wxWidgets_USE_FILE} )

  #Add our own include path
  INCLUDE_DIRECTORIES(
    ${Gel2DE_SOURCE_DIR}/GelCorrelation
    )


#-----------------------------------------------------------------------------
SET(SRCS_GelCorrelation
  src/direntWin.h
  src/direntWin.cpp
  src/File.h
  src/File.cpp
  src/GelCorrelationAnalysis.h
  src/GelCorrelationAnalysis.cpp
  src/GelCorrelationGUI.h
  src/GelCorrelationGUI.cpp
  src/GelImage.h
  src/GelImage.cpp
  src/GelImageStack.h
  src/GelImageStack.cpp
  src/GelImageTransformation.h
  src/GelImageTransformation.cpp
  src/GelImageViewer.h
  src/GelImageViewer.cpp
  src/ProjectConfiguration.h
  src/ProjectConfiguration.cpp
  src/ResultImageViewer.h
  src/ResultImageViewer.cpp
  src/SpearmanRankData.h
  src/SpearmanRankData.cpp
  src/SpearmanRankElement.h
  src/SpearmanRankElement.cpp
  src/SpearmanRankOrderCorrCoeff.h
  src/SpearmanRankOrderCorrCoeff.cpp
  src/StringUtils.h
  src/StringUtils.cpp
  src/TransferFunctionManager.h
  src/TransferFunctionManager.cpp
  src/wxVTKRenderWindowInteractor.h
  src/wxVTKRenderWindowInteractor.cxx
  src/tinystr.h
  src/tinystr.cpp
  src/tinyxml.h
  src/tinyxml.cpp
  src/tinyxmlerror.cpp
  src/tinyxmlparser.cpp
  )

IF(NOT VTK_USE_RENDERING)
  MESSAGE(FATAL_ERROR "Cannot build wxVTK without vtkRendering (vtkWidgets)")
ENDIF(NOT VTK_USE_RENDERING)
LINK_LIBRARIES(
  vtkRendering
  ${wxWidgets_LIBRARIES}
  ${ITK_LIBRARIES}
  )
IF( "${VTK_MAJOR_VERSION}" STREQUAL "5")
  LINK_LIBRARIES( vtkWidgets )
ELSE( "${VTK_MAJOR_VERSION}" STREQUAL "5")
  LINK_LIBRARIES( vtkHybrid )
ENDIF( "${VTK_MAJOR_VERSION}" STREQUAL "5")


ADD_EXECUTABLE(GelCorrelation ${GUI_EXECUTABLE} ${SRCS_GelCorrelation})
GET_TARGET_PROPERTY(GelCorrelation_PATH GelCorrelation LOCATION)

  INSTALL(TARGETS
        GelCorrelation
	RUNTIME DESTINATION bin
	BUNDLE DESTINATION bin
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION lib/static
	)


ELSE(wxWidgets_FOUND)

  MESSAGE("Cannot find wxWidgets libraries and/or header files")

ENDIF(wxWidgets_FOUND)
